package com.probox.modules.controller.product;

import cn.hutool.core.date.DateUtil;
import com.probox.common.core.enums.DataStatus;
import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.product.ProductBuyersshow;
import com.probox.common.entity.domain.product.vo.ProductBuyersshowQuery;
import com.probox.common.entity.service.product.IProductBuyersshowService;
import com.probox.product.api.domain.ProductBuyersshowVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品买家修信息Controller
 *
 * @author usoft
 * @date 2021-09-01
 */
@RestController
@RequestMapping("/product/buyersshow")
public class ProductBuyersshowController extends BaseController {
    @Autowired
    private IProductBuyersshowService productBuyersshowService;

    /**
     * 查询商品买家修信息列表
     */
    @PreAuthorize(hasPermi = "product:buyersshow:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductBuyersshowQuery query) {
        query.setPlatformUid(SecurityUtils.getPlatformId());
        startPage();
        List<ProductBuyersshowVo> list = productBuyersshowService.queryList(query);
        return getDataTable(list);
    }



    /**
     * 获取商品买家修信息详细信息
     */
    @PreAuthorize(hasPermi = "product:buyersshow:query")
    @GetMapping(value = "/{buyersshowUid}")
    public AjaxResult getInfo(@PathVariable("buyersshowUid") Long buyersshowUid) {
        return AjaxResult.success(productBuyersshowService.selectProductBuyersshowById(buyersshowUid));
    }

    /**
     * 新增商品买家修信息
     */
    @PreAuthorize(hasPermi = "product:buyersshow:add")
    @Log(title = "商品买家修信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductBuyersshow productBuyersshow) {
        productBuyersshow.setCreateUid(SecurityUtils.getUserId());
        productBuyersshow.setCreateName(SecurityUtils.getUsername());
        productBuyersshow.setCreateTime(DateUtil.date());
        productBuyersshow.setUpdateUid(SecurityUtils.getUserId());
        productBuyersshow.setUpdateName(SecurityUtils.getUsername());
        productBuyersshow.setUpdateTime(productBuyersshow.getCreateTime());
        productBuyersshow.setPlatformUid(SecurityUtils.getPlatformId());
        productBuyersshow.setDataStatus(DataStatus.valid.getKey());
        productBuyersshow.setCommentTime(productBuyersshow.getCommentTime());
        return toAjax(productBuyersshowService.insertProductBuyersshow(productBuyersshow));
    }

    /**
     * 修改商品买家修信息
     */
    @PreAuthorize(hasPermi = "product:buyersshow:edit")
    @Log(title = "商品买家修信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductBuyersshow productBuyersshow) {
        return toAjax(productBuyersshowService.updateProductBuyersshow(productBuyersshow));
    }

    /**
     * 删除商品买家修信息
     */
    @PreAuthorize(hasPermi = "product:buyersshow:remove")
    @Log(title = "商品买家修信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{buyersshowUids}")
    public AjaxResult remove(@PathVariable Long[] buyersshowUids) {
        return toAjax(productBuyersshowService.deleteProductBuyersshowByIds(buyersshowUids));
    }
}
